<template>
	<view>
		<view>
			<input type="text" placeholder="请输入客户状态名称" v-model="companyName" class="ipt-source">

			<!-- <view class="yes" >确定</view> -->
			<view class="btn-confirm" @tap="handleClickYes">确定</view>
			<!-- <input type="text" v-model="companyName" placeholder="请输入">
			
			<view class="yes" @tap="handleClickYes">确定</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				companyName: '',
				msg: '',
				changeId: '',
			}
		},
		onLoad(option) {
			if (option.item) {
				let list = JSON.parse(option.item)
				this.companyName = list.c_t_name;
				this.changeId = list.id;
			}
		},
		methods: {
			// 取token
			getToken() {
				try {
					const value = uni.getStorageSync('login_key');
					if (value) {
						this.token = value;
					}
				} catch (e) {
					// error
				}
			},
			// 点确定发请求
			async handleClickYes() {
				var pages = getCurrentPages();
				var currPage = pages[pages.length - 1]; //当前页面
				var prevPage = pages[pages.length - 2]; //上一个页面
				//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
				prevPage && prevPage.setData && prevPage.setData({
					isDoRefresh: true
				});
				this.getToken()
				// 发请求
				let url = this.ServicesApi.companyTypeCreateEdit;
				let data = {
					company_type_name: this.companyName,
					id: this.changeId || '', //id有值就是更改，不然就是添加
				};
				if (!this.companyName) {
					return uni.showToast({
						icon: 'none',
						title: '请输入客户状态名称'
					});
				}
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					uni.showToast({
						icon: 'none',
						title: result.msg,
					});
					setTimeout(() => {
						uni.navigateBack({
							delta: 1,
							animationType: 'pop-out',
							animationDuration: 200
						});
					}, 1500);
				} else {
					uni.showToast({
						icon: 'none',
						title: result.msg,
					});
				}
				// uni.request({
				//     url: this.ServicesApi.companyTypeCreateEdit, 
				// 	method:'POST',
				// 	header: {

				// 		"content-type":"application/x-www-form-urlencoded"
				// 	},
				//     data: {
				// 		token:this.token,
				// 		company_type_name:this.companyName,
				// 		id:this.changeId || '',  //id有值就是更改，不然就是添加
				//     },
				//     success: (res) => {
				// 		if(res.data.code == 0){
				// 			uni.showToast({
				// 							icon: 'none',
				// 							title: res.data.msg,
				// 						});
				// 			return false
				// 		}else{
				// 			uni.navigateBack({
				// 				delta: 1,
				// 				animationType: 'pop-out',
				// 				animationDuration: 200
				// 			});
				// 			uni.showToast({
				// 				title: res.data.msg
				// 			});
				// 		}
				// 		// console.log(res.data)
				//     }
				// });
			}
		},
		mounted() {

		}
	}
</script>

<style scoped lang="stylus">
	.msg {
		height: 30upx;
		font-size: 28upx;
		color: red;
	}

	.ipt-source {
		height: 110upx;
		background: #fff;
		padding: 0 40upx;
		font-size: 32upx;
	}

	.btn-confirm {
		height: 76upx;
		width: 440upx;
		background: linear-gradient(270deg, rgba(0, 106, 231, 1) 0%, rgba(66, 157, 255, 1) 100%);
		color: #fff;
		font-size: 32upx;
		text-align: center;
		line-height: 76upx;
		margin: 80upx auto;
	}
</style>
